package 广度优先搜索;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author： li
 * @date： 2022-04-06 08:34
 * @version 1.0
 */

public class 最短路问题 {
    static int x1,x2,y1,y2,n,m;//终点起点
    //状态标记
    static boolean[][] vis = new boolean[105][105];
    //地图
    static int[][] g = new int[105][105];
    //移动方式
    static int[][] next = new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
    static class node{
        private int x;
        private int y;
        private int dis;
        public node(int x, int y, int dis) {
            this.x = x;
            this.y = y;
            this.dis = dis;
        }
    }
    static boolean check(int x,int y){
        return x<1||x>n||y<1||y>m||vis[x][y];
    }
    static int bfs(int x,int y){//起点
        Queue<node> que = new LinkedList<>();
        que.offer(new node(x,y,0));
        vis[x][y]=true;
        while(!que.isEmpty()){
            node p = que.poll();
            if(p.x==x2&&p.y==y2) return p.dis;
            for(int i=0;i<4;i++){
                int tx =p.x+next[i][0];
                int ty =p.y+next[i][1];
                if(check(tx,ty)) continue;
                vis[tx][ty]=true;
                que.offer(new node(tx,ty,p.dis+1));
            }
        }
        return 0;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n =sc.nextInt();m=sc.nextInt();
        x1 =sc.nextInt();
        y1 =sc.nextInt();
        x2 =sc.nextInt();
        y2 =sc.nextInt();
        System.out.println(bfs(x1,y1));
    }
}
